/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaPago.java
 *
 * Created on 29/07/2011, 12:26:22 PM
 */
package co.srm.vistas.funcionales;

import co.srm.entidades.Cliente;
import co.srm.entidades.Cobrador;
import co.srm.entidades.Prestamo;
import co.srm.entidades.Prestamo.EstadoActual;
import co.srm.entidades.Prestamo.ModoPago;
import co.srm.entidades.Usuario;
import co.srm.manejadores.ManejadorCliente;
import co.srm.manejadores.ManejadorCobrador;
import co.srm.manejadores.ManejadorPago;
import co.srm.manejadores.ManejadorPrestamo;
import co.srm.utilidades.Control;
import co.srm.vistas.VentanaPrincipal;
import co.srm.vistas.inicioSesion;
import java.awt.Color;
import java.awt.Font;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author JORGE
 */
public class VentanaPago extends javax.swing.JDialog {

    Cliente cliente = null;
    Prestamo prestamo = null;
    Usuario usuario = null;
    Cobrador cobrador = null;
    public static int ventanaActiva = 0;
    public static String codigoPres = null;
    public static String fechaStr=null;

    /** Creates new form VentanaPago */
    public VentanaPago(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        setLocationRelativeTo(null);
        inicializar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanel6 = new org.jdesktop.swingx.JXPanel();
        jLabel14 = new javax.swing.JLabel();
        panelDatosGenerales = new org.jdesktop.swingx.JXPanel();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        panelPrestamo = new org.jdesktop.swingx.JXPanel();
        jLabel10 = new javax.swing.JLabel();
        campoFechaPrestamo = new org.jdesktop.swingx.JXDatePicker();
        jLabel11 = new javax.swing.JLabel();
        campoMonto = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        campoValorCuota = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        campoPlazo = new javax.swing.JTextField();
        saldoActualLab = new javax.swing.JLabel();
        campoSaldoActual = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        campoNeto = new javax.swing.JTextField();
        jLabelCodigo = new javax.swing.JLabel();
        campoCodigoPrestamo = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        campoInteres = new javax.swing.JLabel();
        jXPanel4 = new org.jdesktop.swingx.JXPanel();
        labelAbono = new javax.swing.JLabel();
        campoAbono = new javax.swing.JTextField();
        panelCliente = new org.jdesktop.swingx.JXPanel();
        campoCedula = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        campoNombre = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        campoTelefono = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        campoFecha = new org.jdesktop.swingx.JXDatePicker();
        comboCobrador = new javax.swing.JComboBox();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        guardarPago = new javax.swing.JButton();
        modificarPago = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        recaudoDia = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jXPanel6.setBackground(new java.awt.Color(255, 220, 98));
        jXPanel6.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true));
        jXPanel6.setForeground(new java.awt.Color(255, 255, 255));

        jLabel14.setFont(new java.awt.Font("Arial", 3, 18));
        jLabel14.setText("Registro De Pagos");

        javax.swing.GroupLayout jXPanel6Layout = new javax.swing.GroupLayout(jXPanel6);
        jXPanel6.setLayout(jXPanel6Layout);
        jXPanel6Layout.setHorizontalGroup(
            jXPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel6Layout.createSequentialGroup()
                .addGap(350, 350, 350)
                .addComponent(jLabel14)
                .addContainerGap(377, Short.MAX_VALUE))
        );
        jXPanel6Layout.setVerticalGroup(
            jXPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelDatosGenerales.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Datos Generales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        panelPrestamo.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Prestamos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jLabel10.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel10.setText("Fecha ");

        campoFechaPrestamo.setEditable(false);

        jLabel11.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel11.setText("Monto");

        campoMonto.setEditable(false);
        campoMonto.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel16.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel16.setText("Plazo");

        campoValorCuota.setEditable(false);
        campoValorCuota.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel17.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel17.setText("Valor Cuota");

        campoPlazo.setEditable(false);
        campoPlazo.setFont(new java.awt.Font("Arial", 0, 12));

        saldoActualLab.setFont(new java.awt.Font("Arial", 1, 12));
        saldoActualLab.setForeground(new java.awt.Color(62, 151, 209));
        saldoActualLab.setText("Saldo Actual");

        campoSaldoActual.setEditable(false);
        campoSaldoActual.setFont(new java.awt.Font("Arial", 0, 12));

        jLabel18.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel18.setText("Neto");

        campoNeto.setEditable(false);
        campoNeto.setFont(new java.awt.Font("Arial", 0, 12));

        jLabelCodigo.setFont(new java.awt.Font("Arial", 0, 12));
        jLabelCodigo.setText("Codigo ");

        campoCodigoPrestamo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoCodigoPrestamoActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel19.setText("%");

        campoInteres.setFont(new java.awt.Font("Arial", 0, 12));

        javax.swing.GroupLayout panelPrestamoLayout = new javax.swing.GroupLayout(panelPrestamo);
        panelPrestamo.setLayout(panelPrestamoLayout);
        panelPrestamoLayout.setHorizontalGroup(
            panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPrestamoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelCodigo)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPrestamoLayout.createSequentialGroup()
                        .addComponent(campoFechaPrestamo, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(campoNeto)
                        .addComponent(campoCodigoPrestamo, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(campoMonto)))
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelPrestamoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                        .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel16)
                            .addComponent(jLabel17)
                            .addComponent(campoInteres, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)))
                    .addGroup(panelPrestamoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saldoActualLab)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoPlazo, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(campoSaldoActual, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                    .addComponent(campoValorCuota, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelPrestamoLayout.setVerticalGroup(
            panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPrestamoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(campoCodigoPrestamo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelCodigo))
                    .addComponent(campoInteres, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel16)
                    .addComponent(campoFechaPrestamo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoPlazo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(campoMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(campoValorCuota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(panelPrestamoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoNeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(saldoActualLab)
                    .addComponent(campoSaldoActual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25))
        );

        jXPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Pago", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        labelAbono.setDisplayedMnemonic('a');
        labelAbono.setFont(new java.awt.Font("Arial", 0, 12));
        labelAbono.setText("Abono");

        campoAbono.setFocusAccelerator('a');
        campoAbono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                campoAbonoKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jXPanel4Layout = new javax.swing.GroupLayout(jXPanel4);
        jXPanel4.setLayout(jXPanel4Layout);
        jXPanel4Layout.setHorizontalGroup(
            jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel4Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(labelAbono)
                .addGap(18, 18, 18)
                .addComponent(campoAbono, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jXPanel4Layout.setVerticalGroup(
            jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelAbono)
                    .addComponent(campoAbono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelCliente.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)), "Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        campoCedula.setEditable(false);

        jLabel4.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel4.setText("Cedula");

        campoNombre.setEditable(false);

        jLabel5.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel5.setText("Nombre");

        jLabel6.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel6.setText("Telefono");

        campoTelefono.setEditable(false);

        javax.swing.GroupLayout panelClienteLayout = new javax.swing.GroupLayout(panelCliente);
        panelCliente.setLayout(panelClienteLayout);
        panelClienteLayout.setHorizontalGroup(
            panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(campoCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(campoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(51, Short.MAX_VALUE))
        );
        panelClienteLayout.setVerticalGroup(
            panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelClienteLayout.createSequentialGroup()
                .addGroup(panelClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(campoCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(campoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(campoTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel12.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel12.setText("Cobrador");

        jLabel8.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel8.setText("Fecha ");

        campoFecha.setEditable(false);

        comboCobrador.setFont(new java.awt.Font("Arial", 0, 12));
        comboCobrador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboCobradorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel2Layout = new javax.swing.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelCliente, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jXPanel2Layout.createSequentialGroup()
                        .addComponent(panelPrestamo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jXPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(campoFecha, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE))
                            .addGroup(jXPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                                .addComponent(comboCobrador, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jXPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel2Layout.createSequentialGroup()
                .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jXPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelPrestamo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jXPanel2Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(campoFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel12)
                            .addComponent(comboCobrador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)
                        .addComponent(jXPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelDatosGeneralesLayout = new javax.swing.GroupLayout(panelDatosGenerales);
        panelDatosGenerales.setLayout(panelDatosGeneralesLayout);
        panelDatosGeneralesLayout.setHorizontalGroup(
            panelDatosGeneralesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosGeneralesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        panelDatosGeneralesLayout.setVerticalGroup(
            panelDatosGeneralesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDatosGeneralesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder()));

        guardarPago.setFont(new java.awt.Font("Arial", 1, 12));
        guardarPago.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/srm/vistas/iconos/guardaricono.png"))); // NOI18N
        guardarPago.setText("Guardar");
        guardarPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guardarPagoActionPerformed(evt);
            }
        });

        modificarPago.setFont(new java.awt.Font("Arial", 1, 12));
        modificarPago.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/srm/vistas/iconos/modificar.png"))); // NOI18N
        modificarPago.setText("Modificar");
        modificarPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificarPagoActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Arial", 1, 12));
        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/srm/vistas/iconos/limpiar2.png"))); // NOI18N
        jButton3.setText("Limpiar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 3, 14));
        jLabel1.setText("RECAUDO DEL DIA");

        recaudoDia.setEditable(false);

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(guardarPago, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(modificarPago, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
            .addComponent(jLabel1)
            .addComponent(recaudoDia, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                .addGap(16, 16, 16))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(recaudoDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
                .addComponent(guardarPago)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(modificarPago)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelDatosGenerales, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23))
            .addComponent(jXPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(panelDatosGenerales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void campoCodigoPrestamoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoCodigoPrestamoActionPerformed
        // TODO add your handling code here:
        if (!campoCodigoPrestamo.getText().isEmpty()) {
            ManejadorPrestamo mp = new ManejadorPrestamo();

            prestamo = mp.consultarPrestamoByCodigo(campoCodigoPrestamo.getText());
//            prestamo=mp.consultarPrestamoById(campoCodigoPrestamo.getText());
            if (prestamo != null) {
                if (prestamo.getEstadoActual().equals(Prestamo.EstadoActual.VIGENTE)) {
                   // panelPrestamo.setBorder(BorderFactory.createLineBorder(Color.BLUE));
                    saldoActualLab.setForeground(Color.BLUE);
                     campoAbono.setEnabled(true);
                    guardarPago.setEnabled(true);
                } else {
                    if (prestamo.getEstadoActual().equals(Prestamo.EstadoActual.VENCIDO)) {
                      //  panelPrestamo.setBorder(BorderFactory.createLineBorder(Color.RED));
                         saldoActualLab.setForeground(Color.RED);
                    } else {
                        if (prestamo.getEstadoActual().equals(Prestamo.EstadoActual.SALDADO)) {
                           // panelPrestamo.setBorder(BorderFactory.createLineBorder(Color.GREEN));
                             saldoActualLab.setForeground(Color.GREEN);
                            campoAbono.setEnabled(false);
                            guardarPago.setEnabled(false);
                        } else {
                          //  panelPrestamo.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
                        }

                    }
                }
                campoFechaPrestamo.setDate(prestamo.getFecha());
                campoInteres.setText(prestamo.getInteres().toString());
                campoMonto.setText(prestamo.getMonto().toString());
                campoPlazo.setText(prestamo.getPlazo().toString());
                campoValorCuota.setText(prestamo.getValorCuota().toString());
                campoNeto.setText(prestamo.getNeto().toString());
                campoSaldoActual.setText(prestamo.getSaldoActual().toString());

                cliente = prestamo.getCliente();
                cobrador = prestamo.getCobrador();
                comboCobrador.setSelectedItem(cobrador);

                campoCedula.setText(cliente.getId().toString());
                campoTelefono.setText(cliente.getTelefono());
                campoNombre.setText(cliente.getNombres());

//                if (prestamo.getEstadoActual().equals(Prestamo.EstadoActual.SALDADO)) {
//                    campoAbono.setEnabled(false);
//                    guardarPago.setEnabled(false);
//                }


            } else {
                limpiar();
                Control.mensajeJOption("No existen Prestamo Asociados a Este Codigo ", "Sin Resultados", 20);
            }
        } else {
            limpiar();
            Control.mensajeJOption("Por favor ingrese el codigo del prestamo", "Campos Vacios", 20);
        }
    }//GEN-LAST:event_campoCodigoPrestamoActionPerformed

    private void comboCobradorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCobradorActionPerformed
        // TODO add your handling code here:
        if (comboCobrador.getSelectedIndex() == 0) {
            Control.disableAndEnabledContainer(panelCliente, false);
        } else if (comboCobrador.getSelectedIndex() >= 1) {
            Control.disableAndEnabledContainer(panelCliente, true);
        }
}//GEN-LAST:event_comboCobradorActionPerformed

    private void guardarPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guardarPagoActionPerformed
        if (campoTelefono.isEnabled() == false || campoAbono.getText().isEmpty() || campoPlazo.getText().isEmpty() || !campoAbono.isEnabled()) {
            Control.mensajeJOption("Hace falta al menos un Procedimiento", "Procedimiento Incompleto", 20);
        } else {
            ManejadorPago mpago = new ManejadorPago();
            Date fecha = campoFecha.getDate();
//            Cobrador cobradorT = (Cobrador) comboCobrador.getSelectedItem();
            usuario = inicioSesion.userActual;
            String abono = campoAbono.getText();
            double abonoAcu = Double.parseDouble(abono);

            boolean guardo = mpago.crearPago(null, abono, fecha, cliente, cobrador, prestamo, usuario, false);
            if (guardo) {
                VentanaPrincipal.totalSesion += abonoAcu;
                recaudoDia.setText(String.valueOf(VentanaPrincipal.totalSesion));
                VentanaPrincipal.recaudoHoy.setText(String.valueOf(VentanaPrincipal.totalSesion));
                limpiar();
                JOptionPane.showMessageDialog(null, "Pago Registrado Exitosamente", "Registro De Pagos", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(null, "No se pudo registrar el Pago", "Registro De Pagos", JOptionPane.WARNING_MESSAGE);
            }
        }
    }//GEN-LAST:event_guardarPagoActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        limpiar();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void campoAbonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoAbonoKeyTyped
        // TODO add your handling code here:
        Control.validaNumeros(evt, campoAbono, 11);
    }//GEN-LAST:event_campoAbonoKeyTyped

    private void modificarPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificarPagoActionPerformed
        // TODO add your handling code here:
        if (!campoCodigoPrestamo.getText().isEmpty()) {
            codigoPres = campoCodigoPrestamo.getText();
            BusquedaPagos bPagos = new BusquedaPagos(null, true);
            bPagos.setVisible(true);
//        BusquedaPagos.idPrestamo.setText(campoCodigoPrestamo.getText());
//        bPagos.llenarTablaPagos();
        } else {
            JOptionPane.showMessageDialog(null, "Falta el codigo del Prestamo", "Registro De Pagos", JOptionPane.WARNING_MESSAGE);
        }

    }//GEN-LAST:event_modificarPagoActionPerformed

    public void cargarCobrador() {
        ManejadorCobrador mCo = new ManejadorCobrador();
        List<Cobrador> cobradores = mCo.todosLosCobradores();
        AutoCompleteDecorator.decorate(comboCobrador);
        comboCobrador.addItem("Seleccione un cobrador");
        for (Cobrador c : cobradores) {
            comboCobrador.addItem(c);

        }
    }

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                VentanaPago dialog = new VentanaPago(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    public void limpiar() {
        campoCedula.setText("");
        campoTelefono.setText("");
        campoNombre.setText("");

        //campoFechaPrestamo.setTimeZone(null);
        campoCodigoPrestamo.setText("");
        campoInteres.setText("");
        campoMonto.setText("");
        campoPlazo.setText("");
        campoValorCuota.setText("");
        campoNeto.setText("");
        campoSaldoActual.setText("");
        campoAbono.setText("");

        comboCobrador.setSelectedIndex(0);

        //panelPrestamo.setBorder(panelDatosGenerales.getBorder());

    }

    public void inicializar() {
        recaudoDia.setText(String.valueOf(VentanaPrincipal.totalSesion));
        cargarCobrador();//cargar los cobradores
        jLabelCodigo.setDisplayedMnemonic('c');
        
        campoCodigoPrestamo.setFocusAccelerator('c');

        labelAbono.setDisplayedMnemonic('a');
        campoAbono.setFocusAccelerator('a');

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField campoAbono;
    private javax.swing.JTextField campoCedula;
    private javax.swing.JTextField campoCodigoPrestamo;
    private org.jdesktop.swingx.JXDatePicker campoFecha;
    private org.jdesktop.swingx.JXDatePicker campoFechaPrestamo;
    private javax.swing.JLabel campoInteres;
    private javax.swing.JTextField campoMonto;
    private javax.swing.JTextField campoNeto;
    private javax.swing.JTextField campoNombre;
    private javax.swing.JTextField campoPlazo;
    private javax.swing.JTextField campoSaldoActual;
    private javax.swing.JTextField campoTelefono;
    private javax.swing.JTextField campoValorCuota;
    private javax.swing.JComboBox comboCobrador;
    private javax.swing.JButton guardarPago;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelCodigo;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXPanel jXPanel4;
    private org.jdesktop.swingx.JXPanel jXPanel6;
    private javax.swing.JLabel labelAbono;
    private javax.swing.JButton modificarPago;
    private org.jdesktop.swingx.JXPanel panelCliente;
    private org.jdesktop.swingx.JXPanel panelDatosGenerales;
    private org.jdesktop.swingx.JXPanel panelPrestamo;
    private javax.swing.JTextField recaudoDia;
    private javax.swing.JLabel saldoActualLab;
    // End of variables declaration//GEN-END:variables
}
